package client;

import mysql.RequeteSql;

import com.trolltech.qt.gui.QDialog;
import com.trolltech.qt.gui.QGridLayout;
import com.trolltech.qt.gui.QGroupBox;
import com.trolltech.qt.gui.QHBoxLayout;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QLineEdit;
import com.trolltech.qt.gui.QMessageBox;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.gui.QVBoxLayout;

public class DiallAddZone extends QDialog {

	
	private QLabel labNomZone, labDescZone;
	private QLineEdit lineNomZone, lineDescZone;
	private QPushButton pushAddZone, pushAnnuler;
	private QGroupBox zoneGroup, butGroup;
	private QGridLayout gridLayout;
	private QHBoxLayout boxButLayout;
	private QGridLayout layout;
	
    private void init()
    {
    	labNomZone = new QLabel("Nom de la Zone");
    	lineNomZone  = new QLineEdit();
    	pushAddZone = new QPushButton("Ajouter");
    	labDescZone = new QLabel("Description");
    	zoneGroup = new QGroupBox(tr("Zone"));
    	new QVBoxLayout();
    	gridLayout = new QGridLayout();
    	lineDescZone = new QLineEdit();
    	boxButLayout = new QHBoxLayout();
    	pushAnnuler = new QPushButton("Annuler");
    	layout = new QGridLayout();
    	butGroup = new QGroupBox();
    }
	
    
    private void arrangeLayout()
    {
    	
    	
    	gridLayout.addWidget(labNomZone, 0, 0);
    	gridLayout.addWidget(lineNomZone, 0, 1);
    	gridLayout.addWidget(labDescZone, 1, 0);
    	gridLayout.addWidget(lineDescZone, 1, 1);
    	
    	boxButLayout.addWidget(pushAddZone);
    	boxButLayout.addWidget(pushAnnuler);
    	
    	zoneGroup.setLayout(gridLayout);
    	butGroup.setLayout(boxButLayout);
    	
    	
    	layout.addWidget(zoneGroup, 0, 0);
    	layout.addWidget(butGroup, 1, 0);
//    	layout.addWidget(pushAddZone, 1 , 0);
    	//layout.addWidget(boxButLayout, 1 , 0);
    	
    }
    
	public DiallAddZone(/*QWidget parent*/)
	{
	  // parent();
		init();
		this.setFixedSize(300, 200);
		arrangeLayout();
		this.pushAddZone.clicked.connect(this, "slotAddZone()");
		this.pushAnnuler.clicked.connect(this, "slotClose()");
		this.setLayout(layout);
	}
	
	
	public void slotAddZone()
	{
		if ((this.lineNomZone.text().compareTo("") != 0))
		{
			if (RequeteSql.zoneRemplieChamp(this.lineNomZone.text(), this.lineDescZone.text()) == false)
			{
				QMessageBox.critical(null, "ERROR", "ERROR REQUETE BASE DE DONNE !!!");
			}
			else
			{
				QMessageBox.information(null, "bravo", "La zone a ete ajoute avec succes");
			}
			
			this.close();
		}
		else
		{
			QMessageBox.critical(null, "bravo", "Veillez remplir les champs !!!");
		}
		
	}
	
	public void slotClose()
	{
		this.close();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//DiallAddZone test = new DiallAddZone();
		//test.show();
		//QApplication.exec();
	}

}
